import 'package:baixing/routers/application.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';


class HotGoods extends StatefulWidget {
  final int page;
  final List<Map> hotGoodsList;

  HotGoods({this.page, this.hotGoodsList});

  @override
  _HotGoodsState createState() =>
      _HotGoodsState(page: page, hotGoodsList: hotGoodsList);
}

class _HotGoodsState extends State<HotGoods> {

  int page = 1;
  List<Map> hotGoodsList;

  _HotGoodsState({this.page, this.hotGoodsList});

  @override
  void initState() {
    super.initState();
    //_getGoodHotGoods();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[
          hotTitle,
          _wrapList(),
        ],
      ),
    );
  }

  Widget hotTitle = Container(
    margin: EdgeInsets.only(top: 10, bottom: 10),
    alignment: Alignment.center,
    color: Colors.transparent,
    child: Text("火爆专区"),
  );

  //火爆专区的Item
  Widget _wrapList() {
    if (hotGoodsList.length != 0) {
      List<Widget> listWidget = hotGoodsList.map((val) {
        return InkWell(
          onTap: () { //路由传递数据
            Application.router.navigateTo(
                context, "detail?id=${val["goodsId"]}");
          },
          child: Container(
            width: ScreenUtil().setWidth(372),
            color: Colors.white,
            padding: EdgeInsets.all(5),
            margin: EdgeInsets.only(bottom: 3),
            child: Column(
              children: <Widget>[
                Image.network(val["image"], width: ScreenUtil().setWidth(370)),
                Text(
                  val["name"],
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(
                    color: Colors.pink,
                    fontSize: ScreenUtil().setSp(26),
                  ),
                ),
                Row(
                  children: <Widget>[
                    Text("￥${val["mallPrice"]}"),
                    Text(
                      "￥${val["price"]}",
                      style: TextStyle(
                          color: Colors.black26,
                          decoration: TextDecoration.lineThrough
                      ),
                    ),
                  ],
                )
              ],
            ),
          ),
        );
      }).toList();

      return Wrap(
        spacing: 2,
        children: listWidget,
      );
    } else {
      return Text("没有更多数据了");
    }
  }

  Widget _hotGoods() {
    return Container(
      child: Column(
        children: <Widget>[
          hotTitle,
          _wrapList(),
        ],
      ),
    );
  }
}
